#ifndef AVALON_SHUTTLEBIMAP_HPP
#define AVALON_SHUTTLEBIMAP_HPP
#include <boost/bimap.hpp>
#include "Avalon/Serialization/Serialization.hpp"

namespace Avalon {
namespace Serialization {

  //! Shuttles a boost::bimap.
  /*!
    \param shuttle The DataShuttle to use.
    \param value The value to shuttle.
    \param version The class version being serialized.
  */
  template<typename K, typename V, typename AP1, typename AP2, typename AP3>
  void Shuttle(DataShuttle* shuttle, boost::bimap<K, V, AP1, AP2, AP3>& value,
      unsigned int version) {
    typedef std::pair<typename boost::bimap<K, V, AP1, AP2, AP3>::left_key_type,
      typename boost::bimap<K, V, AP1, AP2, AP3>::right_key_type> Pair;
    if(shuttle->IsReceiving()) {
      unsigned int count;
      shuttle->Shuttle(count);
      for(unsigned int i = 0; i < count; ++i) {
        Pair entry;
        shuttle->Shuttle(entry);
        value.left.insert(entry);
      }
    } else {
      shuttle->Shuttle(static_cast<unsigned int>(value.size()));
      for(typename boost::bimap<K, V, AP1, AP2, AP3>::left_iterator i =
          value.left.begin(); i != value.left.end(); ++i) {
        shuttle->Shuttle(make_pair(i->first, i->second));
      }
    }
  }
}
}

#endif // AVALON_SHUTTLEBIMAP_HPP
